<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="javascript:;">会议地址列表</a></li>
        <li><a href="{:url('AdminMeeting/addressForm')}">添加地址</a></li>  
    </ul>
    <form class="js-ajax-form" action="" method="post">
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <notempty name="category">
                    <th width="50">{:lang('SORT')}</th>
                </notempty>
                <th width="50">ID</th>
                <th width="15%">所在地区</th>
                <th >详细地址</th>
                <th>默认地址</th>
                <th>状态</th>
                <th>经度</th>
                <th>纬度</th>
                <th width="120">添加时间</th>
                <th width="120">修改时间</th>
                <th width="90">操作</th>
            </tr>
            </thead>
            <empty name="list">
                <td style="text-align:center" colspan="9">无数据</td>
            </empty>
            <foreach name="list" item="vo">
                <tr>
                    <td>
                        <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                               value="{$vo.id}" title="ID:{$vo.id}">
                    </td>
                    <td>{$vo.id}</td>
                    <td>{$vo.area}</td>
                    <td>{$vo.address}</td>
                    <td><if condition="$vo['is_default'] eq 1"><a data-toggle="tooltip" title="默认地址"><i class="fa fa-check"></i></a><else /><i class="fa fa-close fa-fw"></i></if></td>
                    <td><if condition="$vo['status'] eq 1"><a data-toggle="tooltip" title="启用"><i class="fa fa-check"></i></a><else /><i class="fa fa-close fa-fw"></i></if></td>
                    <td>{$vo.lng}</td>
                    <td>{$vo.lat}</td>
                    <td>
                        <notempty name="vo.create_time">
                            {$vo['create_time']}
                        </notempty>
                    </td>
                    <td>
                        <notempty name="vo.update_time">
                            {$vo['update_time']}
                        </notempty
                    </td>
                    <td>
                        <a href="{:url('AdminMeeting/addressForm',array('id'=>$vo['id']))}">{:lang('EDIT')}</a>
                        <a onclick="addressDeleteOne({$vo['id']})">{:lang('DELETE')}</a>
                    </td>
                </tr>
            </foreach>
            <tfoot>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <notempty name="category">
                    <th width="50">{:lang('SORT')}</th>
                </notempty>
                <th width="50">ID</th>
                <th>所在地区</th>
                <th>详细地址</th>
                <th>默认地址</th>
                <th>状态</th>
                <th>经度</th>
                <th>纬度</th>
                <th>添加时间</th>
                <th>修改时间</th>
                <th width="90">操作</th>
            </tr>
            </tfoot>
        </table>
        <div class="table-actions">
        </div>
            <a class="btn btn-danger" id="addressDelete">批量删除</a>
        <ul class="pagination">{$page|default=''}</ul>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script>

    // 批量删除
    $('#addressDelete').on('click', function () {
        var ids = [];
        $("input[name='ids[]']").each(function () {
            if ($(this).is(':checked')) {
                ids.push($(this).val());
            }
        });

        if (ids.length) {
            art.dialog({
                id: 'warning',
                icon: 'warning',
                content: '确定删除吗？',
                cancelVal: '关闭',
                ok: function () {
                   addressDelete(ids)
                }
            });
        } else {
           art.dialog({
                content: '请至少选择一项',
                icon: 'warning',
                ok: function () {
                    this.title('请至少选择一项');
                    return true;
                }
            }); 
        }
    });

    // 单个删除
    function addressDeleteOne(id){
        art.dialog({
            id: 'warning',
            icon: 'warning',
            content: '确定删除吗？',
            cancelVal: '关闭',
            ok: function () {
               addressDelete([id])
            }
        });
    }

    // 执行删除
    function addressDelete(data){
        $.ajax({
            url: "{:url('AdminMeeting/addressDelete')}",
            dataType: 'json',
            data: {id:data},
            type: "POST",
            success: function(data){
                if (data.code == '1') {
                    noty({
                        text: data.msg,
                        type: 'success',
                        layout: 'topCenter',
                        modal: true,
                        timeout: 800,
                        callback: {
                            afterClose: function () {
                                if (data.url) {
                                    //返回带跳转地址
                                    // window.location.href = data.url;
                                    history.go(0) // 当前页面刷新
                                } else {
                                    //刷新当前页
                                    reloadPage(window);
                                }
                            }
                        }
                    }).show();
                } else if (data.code == '0') {
                    art.dialog({
                        content: data.msg,
                        icon: 'warning',
                        ok: function () {
                            this.title(data.msg);
                            return true;
                        }
                    });
                }
            }
        });
    }
</script>
</body>
</html>